/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.model;

import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.bean.TOrder;

/**
 * 说明：会员卡查询Model
 * 
 * @Author：李智深
 * @Date：2012-03-14
 */
public class OrderManageModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas = new Vector<List<Object>>();
	private List<TOrder> tOrderList=new Vector<TOrder>();
	private Vector<String> columns = new Vector<String>();
	
	private boolean[] bools;
	
	public OrderManageModel() {
		columns.add("");
		columns.add("订单编号");
		columns.add("用户名");
		columns.add("用户名称");
		columns.add("手机号");
		columns.add("订单状态");
		columns.add("付款状态");
		columns.add("支付状态");
		columns.add("配送方式");
		columns.add("结束方式");
		columns.add("总金额");
		columns.add("应付金额");
		columns.add("添加时间");
		columns.add("订单来源");
	}

	//获取列对应的类型
	public Class getColumnClass(int column){
		return Object.class;
	}
	//获得行数
	public int getRowCount(){
		return tOrderList.size();
	}
	//获得列数
	public int getColumnCount(){
		return columns.size();
	}
	
	//获得单元格的值
	public Object getValueAt(int row,int column){
//		if (row >= tCommodityList.size())
//			return null;
		TOrder tOrder= tOrderList.get(row);
		return gettCommodityValueByCol(tOrder, row, column);
	}
	
	public Object gettCommodityValueByCol(TOrder tOrder, int row, int column) {
		switch (column) {
			case 0:
				return bools[row];
			case 1:
				return tOrder.getOrderID();//订单编号
			case 2:
				return tOrder.getTUser().getUserName();//用户名;
			case 3:
				return tOrder.getTUser().getRealName();//用户名称
			case 4:
				return tOrder.getTUser().getMobile();//手机号
			case 5:
				return ApplicationContext.ORDER_STATUS_MAP().get(tOrder.getStatus());//订单状态
			case 6:
				return ApplicationContext.PLAY_MATHOD_MAP().get(tOrder.getPayWay());//付款状态
			case 7:
				return ApplicationContext.PLAY_STATUS_MAP().get(tOrder.getPayStatus());//支付状态
			case 8:
				return ApplicationContext.ORDER_SENDWAY_MAP().get(tOrder.getSendWay());//配送方式
			case 9:
				return ApplicationContext.ORDER_ENDWAY_MAP().get(tOrder.getEndWay());//结束方式
			case 10:
				return tOrder.getTotalAmount();//总金额
			case 11:
				return tOrder.getNeedMoney();//应付金额
			case 12:
				return tOrder.getHappenTime();//添加时间
			case 13:
				return ApplicationContext.ORDER_SOURCE_MAP().get(tOrder.getSource());//订单来源
		}
		return null;
	}
	
	//获取列名
	public String getColumnName(int column){
		return (String)columns.get(column);
	}
	
	//设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		if (columnIndex == 0 || columnIndex == 4) 
			return true;
		return false;
	}
	
	public void removeData(int row){
		tOrderList.remove(row);
	}
	//设置单元格的值
	public void setValueAt(Object aValue,int rowIndex,int columnIndex){
		TOrder tOrder= tOrderList.get(rowIndex);
		switch (columnIndex) {
			case 0:
				bools[rowIndex] = (Boolean)aValue;
				return;
		}
		super.setValueAt(aValue, rowIndex, columnIndex);
	}

	public List<TOrder> getTCommodityList() {
		return tOrderList;
	}

	public boolean[] getBools() {
		return bools;
	}
	
	public void setRowData(List<TOrder> tOrderList) {
		this.tOrderList = tOrderList;
		for (int i = tOrderList.size() - 1; i >= 0; --i) {
		}
		bools = new boolean[tOrderList.size()];
	}
}
